<?php
$arr01=[7,3,4,5,2,5,3,7];

/**
 * array_pop() 对原数组进行修改
 * array_push()对原数组进行修改
 * array_shift()对原数组进行修改
 * array_unshift()对原数组进行修改
 * array_unique() 不修改原数组，
 * array_slice()
 * array_splice()对原数组进行修改
 */

//  echo array_pop($arr01)."<br>";
//  echo array_push($arr01,3)."<br>";
 print_r($arr01);
 echo "<br>";
 $arr02=array_unique($arr01);
 print_r($arr02);
 echo "<br>";

 $arr03=array_slice($arr01,3,3);
 print_r($arr03);
 echo "<br>";

 //array_splice的使用当数字不为0时，删除
//  $arr04=array_splice($arr01,3,3);
//  print_r($arr01);
//  echo "<br>";
 $arr04=array_splice($arr01,3,-1,10);
 print_r($arr01);
 echo "<br>";

 /**
  * 数组排序
  *  sort
  *  shuffle
  */

  $arr06=["apple","orange","pear","grape"];
  asort($arr06);
  print_r($arr06);
  echo "<br>";
  shuffle($arr06);
  print_r($arr06);
  echo "<br>";

  /***
   * 其他函数
   * array_keys()
   * array_values()
   * array_reverse()
   * array_merge()
   * array_map()
   * array_reduce()
   */

   $arr07=["a"=>"apple","b"=>"orange","d"=>"pear","f"=>"grape"];

   var_dump(array_keys($arr07));
   echo "<br>";

   var_dump(array_values($arr07));
   echo "<br>";

   echo $arr07["f"]."<br>";

   $arr08=["a","b","c"];
   $arr09=["f","b","c","d"];

   $arr10=array_merge($arr08,$arr09);
   print_r($arr10);
   echo "<br>";
   /***
    * map的使用
    *
    */
$str01="this is a test that is a hello this is test test test test this";
//统计str01字母出现的次数
$arr11=explode(" ",$str01);
print_r($arr11);
$arr12=array_map(function($item){
  return [$item=>1];
},$arr11);

print_r($arr12);
echo "<br>";

$arr13=array_reduce($arr12,function($prev,$curr){
   $currentKey=array_keys($curr)[0];
   if($prev){
   $prevKeys=array_keys($prev);
   $result=in_array($currentKey,$prevKeys);
   if($result){
    $prev[$currentKey]++;
   }else{
    $prev[$currentKey]=1;
   }
  }else{
    $prev[$currentKey]=1;
  }
   return $prev;
});

print_r($arr13);
echo "<br>";